
package protocol.transactions;

import java.lang.reflect.Type;
import java.util.List;

import protocol.XoneProtocol;
import protocol.XoneServiceCode;
import protocol.meta.User;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;
import com.netease.http.THttpRequest;

public class GetPopFriendListTransaction extends XoneBaseTransaction {

    private int mCurrentPage;
    private int mPageSize;
    public GetPopFriendListTransaction(int currentPage, int pageSize) {
        super(TRANSACTION_TYPE_GET_POP_FRIEND_LIST);
        mCurrentPage = currentPage;
        mPageSize = pageSize;
    }

    @Override
    public void onTransact() {
        THttpRequest request = XoneProtocol.getInstance().createGetPopFriendListRequest(mCurrentPage, mPageSize);
        sendRequest(request);
    }

    @Override
    protected void onXoneTransactionSuccess(int code, Object obj) {
        if (obj != null && obj instanceof JsonElement) {
            JsonElement list = ((JsonElement)obj).getAsJsonObject().get("list");
            List<User> userList;
            Gson gson = new Gson();
            Type collectionType = new TypeToken<List<User>>(){}.getType();
            userList = gson.fromJson(list, collectionType);
            notifyMessage(XoneServiceCode.TRANSACTION_SUCCESS, userList);
        } else {
            // TODO
            // notifyError(errCode, arg3)
        }
    }


}
